package com.htthorizon.ws.webservice.conf;



import com.htthorizon.ws.webservice.service.GetKPIValueService;
import com.htthorizon.ws.webservice.service.WSService;
import com.htthorizon.ws.webservice.service.impl.GetKPIValueServiceImpl;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

@Configuration
public class CxfConfig {

    @Autowired
    private Bus bus;

    @Autowired
    private GetKPIValueService getKPIValueService;

    @Autowired
    private WSService wsService;

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }

    @SuppressWarnings("all")
    @Bean
    public ServletRegistrationBean registrationBean(){
        return new ServletRegistrationBean(new CXFServlet(),"/services/*");
    }

    @Bean
    public Endpoint endpoint(){
        EndpointImpl endpoint = new EndpointImpl(bus,getKPIValueService);
        endpoint.publish("/ims");
        return endpoint;
    }


}
